package game.buildings;

import game.resources.Resource;

/**
 *	@(#)Producer.java
 *
 *	The <code>Producer</code> class is a super class for all land
 *	buildings that produce goods. It provides methods to manage the
 *	production and harvest.
 *
 *	@author Grzegorz Kobiela
 *	@version 1.0 2008/4/29
 */
public abstract class Producer
extends LandBuilding
implements Mannable
{
	/** The worker. */
	protected game.Worker worker;

	/** The list of resources. */
	protected java.util.ArrayList<Resource> resources;

	/** The harvest limit. */
	protected int limit;

	/**
	 *	Creates a new <code>Producer</code> instance.
	 *	@param type the building type
	 */
	protected Producer(BuildingType type) {
		super(type);
		resources = new java.util.ArrayList<Resource>();
	}

	/**
	 *	Sets the worker.
	 *	@param worker the worker
	 */
	public void setWorker(game.Worker worker) {
		this.worker = worker;
	}

	/**
	 *	Returns the worker.
	 *	@return the worker
	 */
	public game.Worker getWorker() {
		return worker;
	}

	/**
	 *	Returns true if the building is manned.
	 *	@return true if the building is manned
	 */
	public boolean isManned() {
		return (worker != null);
	}

	/**
	 *	Adds the given resource to the list of resources.
	 *	@param resource the resource
	 */
	public void addResource(Resource resource) {
		resources.add(resource);
	}

	/**
	 *	Removes the given resource from the list of resources.
	 *	@param resource the resource
	 */
	public void removeResource(Resource resource) {
		resources.remove(resource);
		limit--;
	}

	/**
	 *	Returns the list of resources.
	 *	@return the list of resources
	 */
	public java.util.ArrayList<Resource> getResources() {
		return resources;
	}

	/**
	 *	Returns true if all resources were harvested.
	 *	@return true if all resources were harvested
	 */
	public boolean isHarvested() {
		return (limit <= 0 || resources.size() == 0);
	}

	/**
	 *	Sets the harvest counter to the given value.
	 *	@param value the new value
	 */
	public void setLimit(int value) {
		limit = value;
	}
}